
#ifndef __SKYBOX_HPP__
#define __SKYBOX_HPP__

class SkyBox {
	private:
		GLuint m_textureId;
		GLuint m_skyId;
	public:
		SkyBox(string filename, string skyFileName_ = "data/texture/sky.tga") {
			m_textureId = MaterialGestionner::getTexture(filename);
			m_skyId = MaterialGestionner::getTexture(skyFileName_);
		};
		void renderReflect() {
			glPushMatrix();
			glDepthMask(GL_FALSE);
			
			glDisable(GL_DEPTH_TEST);
			glEnable(GL_TEXTURE_2D);
			glBindTexture(GL_TEXTURE_2D, m_skyId);
			glBegin(GL_QUADS);
				/*glTexCoord2f(0.25f,0.33f); glVertex3f(0.0f,0.0f,1.0f);
				glTexCoord2f(0.25f,1.0f); glVertex3f(0.0f,1.0f,1.0f);
				glTexCoord2f(0.5f,1.0f); glVertex3f(1.0f,1.0f,1.0f);
				glTexCoord2f(0.5f,0.33f); glVertex3f(1.0f,0.0f,1.0f);*/
				glTexCoord2f(0.f,0.f); glVertex3f(0.0f,0.0f,1.0f);
				glTexCoord2f(0.f,1.0f); glVertex3f(0.0f,1.0f,1.0f);
				glTexCoord2f(1.f,1.0f); glVertex3f(1.0f,1.0f,1.0f);
				glTexCoord2f(1.f,0.f); glVertex3f(1.0f,0.0f,1.0f);
			glEnd();
			glPopMatrix();


		};

		void render() {
			glPushMatrix();

			glTranslatef(0.0f, 0.0f, 0.f);
			glColor3f(1.0f,1.0f,1.0f);
			glDepthMask(GL_FALSE);
			
			glDisable(GL_DEPTH_TEST);
			// up face
			glEnable(GL_TEXTURE_2D);
			//if (reflect) glScalef(1.0f,1.0f,-1.0f);
			glBindTexture(GL_TEXTURE_2D, m_textureId);
			glBegin(GL_QUADS);
				glTexCoord2f(0.25f,0.33f); glVertex3f(0.0f,1.0f,0.0f);

				glTexCoord2f(0.25f,1.0f); glVertex3f(0.0f,1.0f,1.0f);

				glTexCoord2f(0.5f,1.0f); glVertex3f(1.0f,1.0f,1.0f);

				glTexCoord2f(0.5f,0.33f); glVertex3f(1.0f,1.0f,0.0f);
			glEnd();
			// front face
			glBegin(GL_QUADS);
				glTexCoord2f(0.25f,0.0f); glVertex3f(0.0f,0.5f,1.0f);

				glTexCoord2f(0.25f,0.33f); glVertex3f(0.0f,1.0f,1.0f);

				glTexCoord2f(0.5f,0.33f); glVertex3f(1.0f,1.0f,1.0f);

				glTexCoord2f(0.5f,0.00f); glVertex3f(1.0f,0.5f,1.0f);
			glEnd();
			// left face
			glBegin(GL_QUADS);
				glTexCoord2f(0.0f,0.0f); glVertex3f(0.0f,0.5f,0.0f);

				glTexCoord2f(0.0f,0.33f); glVertex3f(0.0f,1.0f,0.0f);

				glTexCoord2f(0.25f,0.33f); glVertex3f(0.0f,1.0f,1.0f);

				glTexCoord2f(0.25f,0.0f); glVertex3f(0.0f,0.5f,1.0f);
			glEnd();
			// right face
			glBegin(GL_QUADS);
				glTexCoord2f(0.5f,0.0f); glVertex3f(1.0f,0.5f,0.0f);

				glTexCoord2f(0.5f,0.33f); glVertex3f(1.0f,1.0f,0.0f);

				glTexCoord2f(0.75f,0.33f); glVertex3f(1.0f,1.0f,1.0f);

				glTexCoord2f(0.75f,0.0f); glVertex3f(1.0f,0.5f,1.0f);
			glEnd();
			// back face
			glBegin(GL_QUADS);
				glTexCoord2f(0.25f,0.0f); glVertex3f(0.0f,0.5f,0.0f);

				glTexCoord2f(0.25f,0.33f); glVertex3f(0.0f,1.0f,0.0f);

				glTexCoord2f(0.5f,0.33f); glVertex3f(1.0f,1.0f,0.0f);

				glTexCoord2f(0.5f,0.00f); glVertex3f(1.0f,0.5f,0.0f);
			glEnd();
			// on remet en fonctionnement l'écriture dans le depthBufer
			glDepthMask(GL_TRUE);

			glPopMatrix();
		};
};

#endif
